package com.example.oasystem.service.impl;

import com.example.oasystem.dao.mail.AoaMailnumberDaoOfl;
import com.example.oasystem.dao.status.AoaStatusListDao;
import com.example.oasystem.dao.type.AoaTypeListDao;
import com.example.oasystem.entity.mail.AoaInMailListOfSun;
import com.example.oasystem.entity.mail.AoaMailnumberOfl;
import com.example.oasystem.entity.status.AoaStatusList;
import com.example.oasystem.entity.type.AoaTypeList;
import com.example.oasystem.service.AoaMailnumberServiceOfl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AoaMailnumberServiceImplOfl implements AoaMailnumberServiceOfl {

    @Autowired
    AoaMailnumberDaoOfl aoaMailnumberDaoOfl;

    @Autowired
    AoaTypeListDao aoaTypeListDao;

    @Autowired
    AoaStatusListDao aoaStatusListDao;

    @Override
    public PageInfo<AoaMailnumberOfl> mailNumbers(Long mailNumUserId, String baseKey, Integer type, Integer time, Integer status, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        String order="desc";
        if(type!=null&&type==1)
        {
            order="asc";
        }
        if(time!=null&&time==1)
        {
            order="asc";
        }
        if(status!=null&&status==1)
        {
            order="asc";
        }
        List<AoaMailnumberOfl> mailnumbers = aoaMailnumberDaoOfl.mailNumbers(mailNumUserId, baseKey, type, time, status, order);
        PageInfo<AoaMailnumberOfl> pageInfo = new PageInfo<>(mailnumbers);
        return pageInfo;
    }

    @Override
    public PageInfo<AoaMailnumberOfl> mailNumber(Long mailNumUserId, String baseKey, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<AoaMailnumberOfl> mailNumber = aoaMailnumberDaoOfl.mailNumber(mailNumUserId, baseKey);
        PageInfo<AoaMailnumberOfl> pageInfo = new PageInfo<>(mailNumber);
        return pageInfo;
    }

    @Override
    public int deleteByPrimaryKey(Long mailNumberId) {
        return aoaMailnumberDaoOfl.deleteByPrimaryKey(mailNumberId);
    }

    @Override
    public int insertSelective(AoaMailnumberOfl record) {
        return aoaMailnumberDaoOfl.insertSelective(record);
    }

    @Override
    public int updateByPrimaryKeySelective(AoaMailnumberOfl record) {
        return aoaMailnumberDaoOfl.updateByPrimaryKeySelective(record);
    }

    @Override
    public List<AoaStatusList> selectStatusListByRealModel(String statusModel) {
        return aoaStatusListDao.selectStatusListByRealModel(statusModel);
    }

    @Override
    public List<AoaTypeList> selectTypeListByRealModel(String typeModel) {
        return aoaTypeListDao.selectTypeListByRealModel(typeModel);
    }

    @Override
    public AoaMailnumberOfl selectByPrimaryKey(Long mailNumberId) {
        return aoaMailnumberDaoOfl.selectByPrimaryKey(mailNumberId);
    }

    @Override
    public int delMailList(Long mailNumberId) {
        return aoaMailnumberDaoOfl.delMailList(mailNumberId);
    }

    @Override
    public List<AoaInMailListOfSun> mailList(Long mailNumberId) {
        return aoaMailnumberDaoOfl.mailList(mailNumberId);
    }

    @Override
    public int delMailReciver(Long mailId) {
        return aoaMailnumberDaoOfl.delMailReciver(mailId);
    }

    @Override
    public int delAttachment(Long attachmentId) {
        return aoaMailnumberDaoOfl.delAttachment(attachmentId);
    }
}
